home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / Pdev.man < prev    next >
Encoding:
Text File  |  1990-08-27  |  29.4 KB  |  663 lines

  1.  
  2.  
  3.  
  4. Pdev                  C Library Procedures                   Pdev
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NNAAMMEE
  11.      Pdev_Open,        Pdev_Close,        Pdev_SetDefaultHandler,
  12.      Pdev_SetStreamHandler,  Pdev_EnumStreams  - Package for ser-
  13.      vicing pseudo-devices.
  14.  
  15. SSYYNNOOPPSSIISS
  16.      ##iinncclluuddee <<ppddeevv..hh>>
  17.  
  18.      Pdev_Token
  19.      PPddeevv__OOppeenn(_n_a_m_e, _r_e_a_l_N_a_m_e_P_t_r, _r_e_q_B_u_f_S_i_z_e,  _r_e_a_d_B_u_f_S_i_z_e,  _s_e_r_-
  20.      _v_i_c_e, _c_l_i_e_n_t_D_a_t_a)
  21.      void
  22.      PPddeevv__CClloossee(_p_d_e_v_T_o_k_e_n)
  23.      int
  24.      PPddeevv__GGeettSSttrreeaammIIDD(_p_d_e_v_T_o_k_e_n)
  25.      int (*
  26.      PPddeevv__SSeettDDeeffaauullttHHaannddlleerr(_p_d_e_v_T_o_k_e_n, _o_p_e_r_a_t_i_o_n, _h_a_n_d_l_e_r))()
  27.      int (*
  28.      PPddeevv__SSeettSSttrreeaammHHaannddlleerr(_s_t_r_e_a_m_P_t_r, _o_p_e_r_a_t_i_o_n, _h_a_n_d_l_e_r))()
  29.      int
  30.      PPddeevv__EEnnuummSSttrreeaammss(_p_d_e_v_T_o_k_e_n, _f_u_n_c, _c_l_i_e_n_t_D_a_t_a)
  31.  
  32. AARRGGUUMMEENNTTSS
  33.      char             *_n_a_m_e         (in)      Name of file to use
  34.                                               for pseudo-device.
  35.  
  36.      char             **_r_e_a_l_N_a_m_e_P_t_r (out)     Where   to    store
  37.                                               pointer  to  actual
  38.                                               pseudo-device  file
  39.                                               name,  or  NULL  if
  40.                                               _n_a_m_e is to  be  the
  41.                                               complete   name  of
  42.                                               pseudo-device file.
  43.  
  44.      int              _r_e_q_B_u_f_S_i_z_e    (in)      The preferred  size
  45.                                               for         request
  46.                                               buffers.
  47.  
  48.      int              _r_e_a_d_B_u_f_S_i_z_e   (in)      The size for a read
  49.                                               buffer.  Zero means
  50.                                               no read buffering.
  51.  
  52.      Pdev_CallBacks   *_s_e_r_v_i_c_e      (in)      A  set  of  service
  53.                                               call-back      pro-
  54.                                               cedures.
  55.  
  56.      ClientData       _c_l_i_e_n_t_D_a_t_a    (in)      Private       user-
  57.                                               defined data field.
  58.  
  59.      Pdev_Token       _p_d_e_v_T_o_k_e_n     (in)      Token    for    the
  60.  
  61.  
  62.  
  63. Sprite v.1.0        Printed:  August 27, 1990                   1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Pdev                  C Library Procedures                   Pdev
  71.  
  72.  
  73.  
  74.                                               pseudo-device
  75.                                               returned       from
  76.                                               PPddeevv__OOppeenn.
  77.  
  78.      Pdev_Stream      *_s_t_r_e_a_m_P_t_r    (in)      Handle for a stream
  79.                                               to    the   pseudo-
  80.                                               device.
  81.  
  82.      int              _o_p_e_r_a_t_i_o_n     (in)      PPDDEEVV__OOPPEENN,
  83.                                               PPDDEEVV__CCLLOOSSEE,
  84.                                               PPDDEEVV__RREEAADD,
  85.                                               PPDDEEVV__WWRRIITTEE,
  86.                                               PPDDEEVV__IIOOCCTTLL,
  87.                                               PPDDEEVV__SSEETT__AATTTTRR,
  88.                                               PPDDEEVV__GGEETT__AATTTTRR.
  89.  
  90.      int              (*_h_a_n_d_l_e_r)()  (in)      Service   call-back
  91.                                               procedure.
  92.  
  93.      int              (*_f_u_n_c)()     (in)      A procedure applied
  94.                                               to  each  stream to
  95.                                               the pseudo-device.
  96.  
  97. _________________________________________________________________
  98.  
  99. PPddeevv__OOppeenn
  100.      PPddeevv__OOppeenn creates a pseudo-device and installs a set of ser-
  101.      vice  procedures for it.  The pseudo-device can subsequently
  102.      be opened by any number of regular (client)  processes,  and
  103.      the  service  call-backs are made each time a client process
  104.      makes a file system operation on  the  pseudo-device.   Thus
  105.      the  service  call-backs  implement the standard file system
  106.      operations for the  pseudo-device  while  the  Pdev  package
  107.      manages the interface between the kernel and the server pro-
  108.      cess.
  109.  
  110.      There are two ways that PPddeevv__OOppeenn can pick the name  of  the
  111.      file  to use for the pseudo-device.  If _r_e_a_l_N_a_m_e_P_t_r is NULL,
  112.      then PPddeevv__OOppeenn uses _n_a_m_e as the name.  If _r_e_a_l_N_a_m_e_P_t_r  isn't
  113.      NULL,  then  PPddeevv__OOppeenn will generate a file name of the form
  114.      _h_o_s_t_D_i_r//_n_a_m_e_X_X, where _h_o_s_t_D_i_r is  the  name  of  a  standard
  115.      host-specific  directory, _n_a_m_e is the parameter to this pro-
  116.      cedure, and _X_X is a decimal number generated  by  PPddeevv__OOppeenn.
  117.      PPddeevv__OOppeenn  tries  numbers  up from 1 until it finds one that
  118.      works.  The name of the  successful  pseudo-device  file  is
  119.      returned  by  storing  a pointer to it at *_r_e_a_l_N_a_m_e_P_t_r;  the
  120.      storage for the name is dynamically  allocated  with  mmaalllloocc
  121.      and must eventually be freed by the caller.
  122.  
  123.      PPddeevv__OOppeenn returns an opaque token that is used in  calls  to
  124.      PPddeevv__CClloossee,  PPddeevv__SSeettDDeeffaauullttHHaannddlleerr,  and  PPddeevv__EEnnuummSSttrreeaammss.
  125.      If a pseudo-device couldn't be opened, then NULL is returned
  126.      and ppddeevv__EErrrroorrMMssgg contains a string describing the problem.
  127.  
  128.  
  129.  
  130.  
  131. Sprite v.1.0        Printed:  August 27, 1990                   2
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. Pdev                  C Library Procedures                   Pdev
  139.  
  140.  
  141.  
  142.      After a successful PPddeevv__OOppeenn call the Pdev package will  set
  143.      up  a  _s_e_r_v_i_c_e  _s_t_r_e_a_m  whenever  a client process opens the
  144.      pseudo-device.  Each service stream  is  identified  to  the
  145.      call-backs  by a PPddeevv__SSttrreeaamm record.  Thus the pseudo-device
  146.      can be multiplexed over several clients with  each  client's
  147.      request  comming  over a different service stream.  However,
  148.      forks and dups are not visible to the pseudo-device  server,
  149.      so  more than one process might be using any particular ser-
  150.      vice stream.
  151.  
  152.      The _r_e_q_B_u_f_S_i_z_e is used to configure a request buffer associ-
  153.      ated  with  each  service  stream.  This size determines how
  154.      many request messages can be buffered before the  kernel  is
  155.      forced  to  wait  for  them  to  be serviced.  More than one
  156.      request may be outstanding due to asynchronous writes, which
  157.      are  described  below.  A minimum size on the request buffer
  158.      is enforced by the library, so zero can be passed in to  get
  159.      a default size (about 1 Kbyte).
  160.  
  161.      The _r_e_a_d_B_u_f_S_i_z_e is used to configure an optional read buffer
  162.      associated  with  each service stream.  If this size is non-
  163.      zero it indicates that a read buffer will be used to satisfy
  164.      client  read  requests  instead  of  using  the read service
  165.      call-back.  In this case the Pdev package  will  allocate  a
  166.      read  buffer  each time a service stream is created and pass
  167.      the address of this buffer to  the  open  call-back.   After
  168.      that  it  is  up  to  the  server process to manage the read
  169.      buffer.  See the device man page for ppddeevv for details.
  170.  
  171.      The _c_l_i_e_n_t_D_a_t_a parameter to PPddeevv__OOppeenn is passed to the  open
  172.      call-back  as  described below.  It is meant to be used as a
  173.      pointer back to some top-level state of the pseudo-device.
  174.  
  175.      The Pdev package uses the facilities of FFss__DDiissppaattcchh in order
  176.      to  keep  track  of  the streams associated with the pseudo-
  177.      device and ensure  that  Pdev  is  notified  whenever  those
  178.      streams  become  readable.   In  order to use Pdev, you must
  179.      also use FFss__DDiissppaattcchh.
  180.  
  181. PPddeevv__CClloossee
  182.      PPddeevv__CClloossee shuts  down  a  pseudo-device,  closing  all  the
  183.      streams associated with it and releasing any resources allo-
  184.      cated to the pseudo-device.   As  a  side-effect  the  close
  185.      call-back  is  made  to any existing service streams.  After
  186.      this procedure  returns,  _p_d_e_v_T_o_k_e_n  should  never  be  used
  187.      again.
  188.  
  189. PPddeevv__GGeettSSttrreeaammIIDD
  190.      PPddeevv__GGeettSSttrreeaammIIDD  returns  the  identifier  for  the  stream
  191.      associated  with  the token returned by PPddeevv__OOppeenn.  This may
  192.      be used for stream-oriented calls such as ffssttaatt  but  should
  193.      not  be  used as the argument to cclloossee (PPddeevv__CClloossee should be
  194.  
  195.  
  196.  
  197. Sprite v.1.0        Printed:  August 27, 1990                   3
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. Pdev                  C Library Procedures                   Pdev
  205.  
  206.  
  207.  
  208.      used instead.)
  209.  
  210. PPddeevv__EEnnuummSSttrreeaammss
  211.      The PPddeevv__EEnnuummSSttrreeaammss procedure is used to apply  a  function
  212.      to  all  the  service  streams  to  the pseudo-device.  This
  213.      enumeration procedure eliminates the need to keep  track  of
  214.      each  service  stream.   The _f_u_n_c argument is called on each
  215.      service stream as follows:
  216.  
  217.           int
  218.           (*func)(streamPtr, clientData)
  219.               Pdev_Stream *streamPtr;
  220.               ClientData clientData;
  221.  
  222.      Where _s_t_r_e_a_m_P_t_r identifies the service stream,  and  _c_l_i_e_n_t_-
  223.      _D_a_t_a  is  what  was passed to PPddeevv__EEnnuummSSttrreeaammss.  _f_u_n_c should
  224.      return zero to mean success, or a non-zero error status.  In
  225.      the  case of an error PPddeevv__EEnnuummSSttrreeaammss stops its enumeration
  226.      and returns the non-zero status.
  227.  
  228. PPddeevv__SSeettDDeeffaauullttHHaannddlleerr
  229.      PPddeevv__SSeettDDeeffaauullttHHaannddlleerr is used  to  set  the  call-back  for
  230.      individual  pdev  operations.   It is not normally needed as
  231.      you  can  define  all  the  call-backs  with  PPddeevv__OOppeenn  (or
  232.      PPffss__OOppeennCCoonnnneeccttiioonn).  The call-backs passed to PPddeevv__OOppeenn are
  233.      inherited by each service stream that is created.   Changing
  234.      a  call-back  with  PPddeevv__SSeettDDeeffaauullttHHaannddlleerr changes the call-
  235.      back for  all  subsequently  created  service  streams.   It
  236.      doesn't  affect  any  service streams that are already esta-
  237.      blished.  This returns the old default call-back.
  238.  
  239. PPddeevv__SSeettSSttrreeaammHHaannddlleerr
  240.      PPddeevv__SSeettSSttrreeaammHHaannddlleerr is used to  set  a  call-back  for  an
  241.      already  existing  service stream.  It returns the old call-
  242.      back.
  243.  
  244. SSEERRVVIICCEE PPRROOCCEEDDUURREESS
  245.      The call-back service procedures are given to PPddeevv__OOppeenn (and
  246.      PPffss__OOppeennCCoonnnneeccttiioonn) as a record of procedures:
  247.  
  248.           typedef struct {
  249.               int (*open)();            /* PDEV_OPEN */
  250.               int (*read)();            /* PDEV_READ */
  251.               int (*write)();           /* PDEV_WRITE and PDEV_WRITE_ASYNC */
  252.               int (*ioctl)();           /* PDEV_IOCTL */
  253.               int (*close)();           /* PDEV_CLOSE */
  254.               int (*getAttr)();         /* PDEV_GET_ATTR */
  255.               int (*setAttr)();         /* PDEV_SET_ATTR */
  256.           } Pdev_CallBacks;
  257.  
  258.      Any of the record elements can be NULL to indicate that  the
  259.      operation  should  be  handled  by  a  default handler.  The
  260.  
  261.  
  262.  
  263. Sprite v.1.0        Printed:  August 27, 1990                   4
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. Pdev                  C Library Procedures                   Pdev
  271.  
  272.  
  273.  
  274.      _s_e_r_v_i_c_e parameter  itself  can  also  be  NULL  to  indicate
  275.      default  handling  for  all operations.  This is only useful
  276.      during initial test.  If a client  makes  an  operation  for
  277.      which no service procedure is provided it is simply a no-op;
  278.      it is not an error.  The global variable ppddeevv__TTrraaccee  can  be
  279.      set  to  a non-zero value to generate printfs to stderr when
  280.      each  service  procedure  (default  or   user-supplied)   is
  281.      invoked.
  282.  
  283.      Service procedures should return  zero  to  mean  successful
  284.      completion,  otherwise  they  should  return  an appropriate
  285.      errno value.  Additionally, the rreeaadd  and  wwrriittee  procedures
  286.      use  EEWWOOUULLDDBBLLOOCCKK to indicate incomplete operations.  This is
  287.      described further below.
  288.  
  289.      Each service procedure also sets the  current  select  state
  290.      bits for the pseudo-device.  The select bits are used in the
  291.      kernel's implementation of sseelleecctt for pseudo-devices.   They
  292.      should   be   a   bitwise  or  combination  of  FFSS__RREEAADDAABBLLEE,
  293.      FFSS__WWRRIITTAABBLLEE, and FFSS__EEXXCCEEPPTTIIOONN.   As  well  as  setting  this
  294.      select  state  after  each  client  operation, it may be set
  295.      asynchronously with the IIOOCC__PPDDEEVV__RREEAADDYY iiooccttll command on  the
  296.      service stream.
  297.  
  298.      These same service procedures  are  used  for  pseudo-device
  299.      connections  into  the pseudo-file-system.  See PPffss__OOppeenn and
  300.      PPffss__OOppeennCCoonnnneeccttiioonn.  The ggeettAAttttrr and sseettAAttttrr call-backs  are
  301.      only   made  to  pseudo-file-system  servers.   For  regular
  302.      pseudo-devices the kernel takes care of all  attribute  han-
  303.      dling.
  304.  
  305. ooppeenn
  306.           int
  307.           (*service->open)(clientData, streamPtr, readBuffer, flags, procID,
  308.                hostID, uid, selectBitsPtr)
  309.               ClientData clientData;    /* Private data passed to Pdev_Open */
  310.               Pdev_Stream *streamPtr;   /* Identifies stream to pseudo-device. */
  311.               char *readBuffer;         /* Storage for optional read buffer */
  312.               int flags;                /* Flags to the open system call. NOTE!
  313.                                          * These are Sprite flags defined in <fs.h>,
  314.                                          * not the Unix flags defined in <sys/file.h> */
  315.               int procID;               /* ID of process opening the pseudo-device */
  316.               int hostID;               /* Host where that process is executing */
  317.               int uid;                  /* User ID of that process */
  318.               int *selectBitsPtr;       /* Return - the initial select state of the process */
  319.  
  320.      When a client process makes  an  ooppeenn  system  call  on  the
  321.      pseudo-device the Pdev library package invokes the ooppeenn ser-
  322.      vice call-back to give the server  a  chance  to  refuse  or
  323.      accept  the open by the client process.  The return value of
  324.      the open call-back is either 0 for success, or an  appropri-
  325.      ate errno value.
  326.  
  327.  
  328.  
  329. Sprite v.1.0        Printed:  August 27, 1990                   5
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. Pdev                  C Library Procedures                   Pdev
  337.  
  338.  
  339.  
  340.      The ooppeenn call-back gets passed the _c_l_i_e_n_t_D_a_t_a that was given
  341.      to  the  PPddeevv__OOppeenn  procedure, and a new _s_t_r_e_a_m_P_t_r that is a
  342.      handle on the service stream corresponding to  the  open  by
  343.      the  client.  _s_t_r_e_a_m_P_t_r is a pointer to a PPddeevv__SSttrreeaamm record
  344.      that contains a cclliieennttDDaattaa field for use by the  call-backs,
  345.      and a ssttrreeaammIIDD field that is used in iiooccttll calls on the ser-
  346.      vice stream.  The possible iiooccttll calls are listed at the end
  347.      of  this  man  page.   The  _s_t_r_e_a_m_P_t_r gets passed to all the
  348.      other    call-backs,    and    is     also     passed     to
  349.      PPddeevv__SSeettSSttrreeaammHHaannddlleerr.
  350.  
  351.      The parameters also  include  the  useFlags  passed  to  the
  352.      FFss__OOppeenn  system  call,  and the user ID and Sprite hostID of
  353.      the client process.  (FFss__OOppeenn is the Sprite version of ooppeenn.
  354.      The  flag  bits  are  different  and  are defined in <fs.h>.
  355.      Flags passed to ooppeenn are mapped  to  the  Sprite  flag  bits
  356.      you'll  get here.) If the _r_e_a_d_B_u_f_S_i_z_e parameter to PPddeevv__OOppeenn
  357.      was non-zero then Pdev allocates _r_e_a_d_B_u_f_f_e_r and passes it to
  358.      the  open call-back.  Thus there will be one read buffer for
  359.      each service stream  if  the  server  is  implementing  read
  360.      buffering.
  361.  
  362. cclloossee
  363.           int
  364.           (*service->close)(streamPtr)
  365.               Pdev_Stream *streamPtr;   /* Identifies service stream */
  366.  
  367.      This is called when a service stream is closed.   This  hap-
  368.      pens  either  as  a  side  effect of PPddeevv__CClloossee, or when the
  369.      client has closed is last reference to the  service  stream.
  370.      (Dups and forks are not visible to the pseudo-device server,
  371.      so there is only one close per open system call by a  client
  372.      process.)
  373.  
  374. rreeaadd
  375.           int
  376.           (*service->read)(streamPtr, readPtr, freeItPtr, selectBitsPtr, sigPtr)
  377.               Pdev_Stream *streamPtr;   /* Identifies service stream */
  378.               Pdev_RWParam *readPtr;    /* Read parameter block */
  379.               Boolean *freeItPtr;       /* Set to TRUE if buffer should be free'd */
  380.               int *selectBitsPtr;       /* Return - select state of the pseudo-device */
  381.               Pdev_Signal *sigPtr;      /* Return - signal to generate, if any */
  382.  
  383.      The read service  procedure  is  passed  a  record  of  type
  384.      PPddeevv__RRWWPPaarraamm  that  indicates the lleennggtthh, ooffffsseett, and bbuuffffeerr
  385.      for the read.  The  buffer  is  pre-allocated  by  the  PPddeevv
  386.      library.   If the read service procedure wants to use a dif-
  387.      ferent buffer it can change _r_e_a_d_P_t_r-->>bbuuffffeerr to reference its
  388.      own  storage.   If  this  different storage area ought to be
  389.      freed  after  the  library  completes  the  operation,  then
  390.      *_f_r_e_e_I_t_P_t_r should be set to a non-zero value.
  391.  
  392.  
  393.  
  394.  
  395. Sprite v.1.0        Printed:  August 27, 1990                   6
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. Pdev                  C Library Procedures                   Pdev
  403.  
  404.  
  405.  
  406.      The _r_e_a_d_P_t_r-->>lleennggtthh record field indicates how much data  is
  407.      requested, and it should be updated to reflect the amount of
  408.      data actually returned.  If there is no  data  available  on
  409.      the  pseudo-device  then  the  read  call-back should return
  410.      EEWWOOUULLDDBBLLOOCCKK and set _r_e_a_d_P_t_r-->>lleennggtthh to  zero.   This  causes
  411.      the  kernel  to  block  the  client process until the select
  412.      state of the pseudo-device is changed to indicate  readabil-
  413.      ity.   If  there  are  some bytes available the return value
  414.      should be zero and _r_e_a_d_P_t_r-->>lleennggtthh  set  appropriately.   If
  415.      the  read  leaves  no  additional  bytes  available then the
  416.      FFSS__RREEAADDAABBLLEE bit can be cleared from *_s_e_l_e_c_t_B_i_t_s_P_t_r in  order
  417.      to block the next read request.  End-of-file is indicated to
  418.      the client by a zero return code and a zero number of  bytes
  419.      returned.
  420.  
  421.      A signal can be generated in response to a read  request  by
  422.      setting  _s_i_g_P_t_r-->>ssiiggnnaall  to  a non-zero value.  _s_i_g_P_t_r-->>ccooddee
  423.      can also be set to modify the signal meaning.  Data  can  be
  424.      returned if a signal is generated.  The client application's
  425.      system call will complete, its signal handler, if any,  will
  426.      be invoked, and the system call will be retried.
  427.  
  428.      Note:  If there is a read buffer associated with the service
  429.      stream,  which is indicated by a non-zero valued _r_e_a_d_B_u_f_S_i_z_e
  430.      parameter to PPddeevv__OOppeenn, then this read  call-back  is  never
  431.      called.   Instead  the  kernel  takes data directly from the
  432.      read buffer.  The protocol  for  adding  data  to  the  read
  433.      buffer is described in the ppddeevv device man page.
  434.  
  435. wwrriittee
  436.           int
  437.           (*service->write)(streamPtr, async, writePtr, selectBitsPtr, sigPtr)
  438.               Pdev_Stream *streamPtr;   /* Identifies service stream */
  439.               int async;                /* TRUE during an asynchronous write */
  440.               Pdev_RWParam *writePtr;   /* Write parameter block */
  441.               int *selectBitsPtr;       /* Return - select state of the pseudo-device */
  442.               Pdev_Signal *sigPtr;      /* Return - signal to generate, if any */
  443.  
  444.      The write service procedure is passed a parameter block that
  445.      indicates  the lleennggtthh, ooffffsseett, and bbuuffffeerr for the operation,
  446.      plus various IDs of the application process.   If  _a_s_y_n_c  is
  447.      FFAALLSSEE  (zero)  then  _w_r_i_t_e_P_t_r-->>lleennggtthh  should  be updated to
  448.      reflect how much data was  processed  by  the  service  pro-
  449.      cedure.   If  _a_s_y_n_c is non-zero it indicates an asynchronous
  450.      write and the service procedure must accept all of the  data
  451.      and the return value of _w_r_i_t_e_P_t_r-->>lleennggtthh is ignored.
  452.  
  453.      If the server cannot accept all of the data it  must  return
  454.      EEWWOOUULLDDBBLLOOCCKK _a_n_d update _w_r_i_t_e_P_t_r-->>lleennggtthh to indicate just how
  455.      much data it accepted.  This return value causes the  kernel
  456.      to  block  the  client process until the select state of the
  457.      pseudo-device  is  changed  to  indicate  writability.    To
  458.  
  459.  
  460.  
  461. Sprite v.1.0        Printed:  August 27, 1990                   7
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. Pdev                  C Library Procedures                   Pdev
  469.  
  470.  
  471.  
  472.      repeat, returning a short write count and a zero return code
  473.      will cause the kernel to  immediately  issue  another  write
  474.      request  to  complete the client's write operation.  By also
  475.      returning EEWWOOUULLDDBBLLOOCCKK the pseudo-device  server  forces  the
  476.      client process to wait until the pseudo-device becomes writ-
  477.      able.
  478.  
  479.      A signal to the client application can  be  generated  as  a
  480.      side  effect  by setting _s_i_g_P_t_r-->>ssiiggnnaall to a non-zero value.
  481.      _s_i_g_P_t_r-->>ccooddee can be set to modify the signal.  Data  can  be
  482.      accepted  by the write service procedure if a signal is gen-
  483.      erated.  The client application's write call will  complete,
  484.      its  signal  handler, if any, will be invoked, and the write
  485.      call will be retried.
  486.  
  487. iiooccttll
  488.           int
  489.           (*service->ioctl)(streamPtr, ioctlPtr, selectBitsPtr, sigPtr)
  490.               Pdev_Stream *streamPtr;   /* Set by open service procedure */
  491.               Pdev_IOCParam *ioctlPtr;  /* I/O Control parameter block */
  492.               int *selectBitsPtr;       /* Return - select state of pdev */
  493.               Pdev_Signal *sigPtr;      /* Return - signal to generate, if any */
  494.  
  495.      The ioctl service procedure takes  a  parameter  block  that
  496.      specifies the ccoommmmaanndd, and two buffers, one containing input
  497.      data (iinnBBuuffffeerr), and one for data  returned  to  the  client
  498.      (oouuttBBuuffffeerr).    The  ioctl  service  has  to  set  _i_o_c_t_l_P_t_r--
  499.      >>oouuttBBuuffSSiizzee to indicate how much data is being  returned  to
  500.      the  client process.  The PPddeevv__IIOOCCPPaarraamm struct also contains
  501.      various processIDs, and the ffoorrmmaatt of the host on which  the
  502.      client application is executing.
  503.  
  504.      The pseudo-device server can implement any _i_o_c_t_l_P_t_r-->>ccoommmmaanndd
  505.      it wants.  Generic commands are defined in <fs.h>, and other
  506.      ranges of commands for particular devices and pseudo-devices
  507.      are defined in header files in /sprite/src/lib/include/dev.
  508.  
  509.      The input and output data is not byteswapped by the  operat-
  510.      ing system.  It is the server's responsibility to fix up the
  511.      input and output buffers in the case that the client  has  a
  512.      different  byte  order.   The local byte order is defined as
  513.      MMAACCHH__BBYYTTEE__OORRDDEERR by  <machparam.h>,  and  the  client's  byte
  514.      order  and alignment are indicated by _i_o_c_t_l_P_t_r-->>ffoorrmmaatt.  The
  515.      FFmmtt__CCoonnvveerrtt library routine can be used to  swap  and  align
  516.      incomming and outgoing buffers.
  517.  
  518.      A signal to the client application can  be  generated  as  a
  519.      side  effect  by setting _s_i_g_P_t_r-->>ssiiggnnaall to a non-zero value.
  520.      _s_i_g_P_t_r-->>ccooddee can be set to modify the signal.
  521.  
  522. ggeettAAttttrr
  523.           int
  524.  
  525.  
  526.  
  527. Sprite v.1.0        Printed:  August 27, 1990                   8
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534. Pdev                  C Library Procedures                   Pdev
  535.  
  536.  
  537.  
  538.           GetAttrProc(streamPtr, attrPtr, selectBitsPtr)
  539.               Pdev_Stream *streamPtr;   /* Identifies service stream */
  540.               Fs_Attributes *attrPtr;   /* Return - attributes */
  541.               int *selectBitsPtr;       /* Return - select state of the pseudo-device */
  542.  
  543.      This procedure is called to handle an fstat() call on a file
  544.      in a pseudo-file system.  The _s_t_r_e_a_m_P_t_r parameter identifies
  545.      the open stream, and the server should fill  in  the  attri-
  546.      butes.   This call-back is not made to regular pseudo-device
  547.      servers, only to pseudo-file-system servers.
  548.  
  549. sseettAAttttrr
  550.           int
  551.           SetAttrProc(streamPtr, flags, uid, gid, attrPtr, selectBitsPtr)
  552.               Pdev_Stream *streamPtr;   /* Identifies service stream */
  553.               int flags;                /* Indicate what attributes to set */
  554.               int uid;                  /* Identifies user making the call */
  555.               int gid;                  /* Identifies group of process */
  556.               Fs_Attributes *attrPtr;   /* Attributes to set as indicated by flags */
  557.               int *selectBitsPtr;       /* Return - select state of the pseudo-device */
  558.  
  559.      This procedure is called to set  certain  attributes  of  an
  560.      open  file in a pseudo-file system.  The _s_t_r_e_a_m_P_t_r parameter
  561.      identifies the open stream.  The flags argument contains  an
  562.      or'd     combinantion    of    FFSS__SSEETT__TTIIMMEESS,    FFSS__SSEETT__MMOODDEE,
  563.      FFSS__SSEETT__OOWWNNEERR, FFSS__SSEETT__FFIILLEE__TTYYPPEE, FFSS__SSEETT__DDEEVVIICCEE that  indicate
  564.      what  attributes to set.  The attribute values are contained
  565.      in *_a_t_t_r_P_t_r.  The _u_i_d and _g_i_d arguments identify the calling
  566.      process.   This  call-back  is  not  made to regular pseudo-
  567.      device servers, only to pseudo-file-system servers.
  568.  
  569. SSeerrvviiccee SSttrreeaamm IIooccttllss
  570.      The pseudo-device server can make a few  FFss__IIOOCCoonnttrrooll  calls
  571.      on   its  service  streams.   The  details  of  the  calling
  572.      sequences is described in the device man  page  for  pseduo-
  573.      devices (pdev).  The possible operations are:
  574.  
  575.      IOC_PDEV_READY
  576.           Used to change the select state of  the  pseudo-device.
  577.           The input buffer to Fs_IOControl should contain an or'd
  578.           combination    of    FFSS__RREEAADDAABBLLEE,    FFSS__WWRRIITTAABBLLEE,    or
  579.           FFSS__EEXXCCEEPPTTIIOONN.
  580.  
  581.      IOC_PDEV_SIGNAL_OWNER
  582.           Used to send a signal to the owning process or  process
  583.           group  of the pseudo-device.  This is useful for imple-
  584.           menting interrupt characters in tty emulators.  No spe-
  585.           cial permission is needed.
  586.  
  587.      IOC_PDEV_WRITE_BEHIND
  588.           Used to set or unset asynchronous writing.
  589.  
  590.  
  591.  
  592.  
  593. Sprite v.1.0        Printed:  August 27, 1990                   9
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. Pdev                  C Library Procedures                   Pdev
  601.  
  602.  
  603.  
  604.      IOC_PDEV_BIG_WRITES
  605.           Used to  allow  or  disallow  writes  larger  than  the
  606.           request buffer.
  607.  
  608.      IOC_PDEV_SET_PTRS
  609.           Used to adjust pointers into the read  buffer  and  the
  610.           request  buffer.  Users of the Pdev package should only
  611.           use this to adjust read  buffer  pointers.   Leave  the
  612.           request  buffer  pointers equal to -1 so you don't mess
  613.           up the managing of the request buffer.
  614.  
  615.      For example:
  616.  
  617.           status = Fs_IOControl(streamPtr->streamID, IOC_PDEV_READY,
  618.                         sizeof(int), &selectBits, 0, NULL);
  619.  
  620. SSEEEE AALLSSOO
  621.      pdev (devices), Pfs, Swap_Buffer
  622.  
  623. KKEEYYWWOORRDDSS
  624.      pseudo-device
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659. Sprite v.1.0        Printed:  August 27, 1990                  10
  660.  
  661.  
  662.  
  663.